﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
using System.Reflection;
using log4net;


[assembly: log4net.Config.XmlConfigurator(Watch = true)]
namespace VipTest
{
    class Request
    {
        ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        public Socket conn { get; set; }
        public string strRequest { get; set; }
        public byte[] byteRequest { get; set; }
        public List<byte[]> lstRequest { get; set; }
        public DateTime dtNow { get; private set; }
        public Byte[] byteRecv { get; private set; }
        public string strRecv { get; private set; }
        public int bytes { get; private set; }

        public void sendRequest()
        {
            //Byte[] RecvBytes = new Byte[256];
            //string strRecvString = "";
            //int bytes = 0;
            this.dtNow = DateTime.Now;
            log.Info("Sending Request...");
            this.conn.Send(this.byteRequest);
            bytes = conn.Receive(this.byteRecv, this.byteRecv.Length, 0);
            log.Info("Data Received. Used " + DateTime.Now.Subtract(this.dtNow).TotalMilliseconds.ToString() + "ms.");
            strRecv = System.Text.Encoding.GetEncoding("GB2312").GetString(this.byteRecv, 0, bytes);
            log.Info(strRecv);
        }

        public void sendRequests()
        {
            //Byte[] RecvBytes = new Byte[256];
            //string strRecvString = "";
            //int bytes = 0;
            this.dtNow = DateTime.Now;

            foreach (byte[] request in this.lstRequest)
            {
                //dtStart = DateTime.Now;
                this.conn.Send(request);
                bytes = conn.Receive(this.byteRecv, this.byteRecv.Length, 0);
                //log.Info("Data Received. Used " + DateTime.Now.Subtract(dtStart).TotalMilliseconds.ToString() + "ms.");
                log.Info("Data Received.");
                //strRecvString = System.Text.Encoding.GetEncoding("GB2312").GetString(RecvBytes, 0, bytes);
                //log.Info(strRecvString);
            }
        }

        public Request()
        { 
            byteRecv = new Byte[256];
        }
    }
}
